package com.fz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.entity.ParkingSpace;
import com.fz.service.ParkingSpaceService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 存储车位及绑定用户信息 前端控制器
 * </p>
 *
 * @author hyr
 * @since 2025-06-18
 */
@RestController
@RequestMapping("/parkingSpace")
public class ParkingSpaceController {
    @Resource
    ParkingSpaceService parkingSpaceService;
    @GetMapping("/list")
    List<ParkingSpace> list(){
        return parkingSpaceService.list();
    }
    @GetMapping("/list1")
    public ResultVo<List<ParkingSpace>> list1() {
        return ResultVo.success(parkingSpaceService.list(), "查询成功");
    }
    @PostMapping("/add")
    ResultVo<Boolean> add(ParkingSpace parkingSpace){
        return ResultVo.success(parkingSpaceService.save(parkingSpace),"车位申请提交成功！");
    }
    @PostMapping("/update")
    ResultVo<Boolean> update(Long id, String carNumber, String username, Integer occupied){
        return ResultVo.success(parkingSpaceService.update(id,carNumber,username,occupied),"车位申请提交成功！");
    }
    @PostMapping("/del")
    ResultVo<Boolean> del(Long id){
        return ResultVo.success(parkingSpaceService.del(id),"车位申请撤回成功！");
    }
    @PostMapping("/pass")
    ResultVo<Boolean> pass(Long id,Integer status){
        return ResultVo.success(parkingSpaceService.pass(id,status),"车位申请通过成功！");
    }
    @PostMapping("/reject")
    ResultVo<Boolean> reject(Long id,Integer status){
        return ResultVo.success(parkingSpaceService.reject(id,status),"车位申请驳回成功！");
    }
    //    @PostMapping("/search")
//    ResultVo<List<ParkingSpace>> search(String input){
//        return ResultVo.success(parkingSpaceService.search(input),"搜索成功");
//    }
    @PostMapping("/list2")
    ResultVo<IPage<ParkingSpace>> list2(Integer pageNo, Integer pageSize){
        return ResultVo.success(parkingSpaceService.showList2( pageNo, pageSize));
    }

    @PostMapping("/search")
    ResultVo<IPage<ParkingSpace>> search(String input,Integer pageNo, Integer pageSize){
        return ResultVo.success(parkingSpaceService.search(input,pageNo,pageSize),"搜索成功！");
    }
    @GetMapping("/check")
    public ResultVo<Boolean> checkcarnumber(String field, String value) {
        return ResultVo.success(parkingSpaceService.check(field,value));
    }
}
